﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp001
{
    class DbHelper

    {
        private static readonly string conString = "server=LAPTOP-47B7TGQ4\\SQLEXPRESS;database=Blogs;uid=sa;pwd=2113144056";

        public static DataTable GetDataTable(string sql)
        {
            string conString = "server=LAPTOP-47B7TGQ4\\SQLEXPRESS;database=Blogs;uid=sa;pwd=2113144056";

            SqlConnection sqlConnection = new SqlConnection(conString);

           
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConnection);

            DataTable dt = new DataTable();

            sqlConnection.Open();

            dataAdapter.Fill(dt);

            return dt;
        }
        //增加和修改方法
        public static int AddOrEditOrDeleteSave(string sql)
        {
            //初始化连接
            SqlConnection sqlConnection = new SqlConnection(conString);
            //初始化对象
            SqlCommand command = new SqlCommand(sql, sqlConnection);

            sqlConnection.Open();

            return command.ExecuteNonQuery();

            
        }
    }
}
